package com.yvon.service.demo.spring.beans;

import java.util.ArrayList;
import java.util.List;

/**
 * 属性值(列表)
 *
 * @author : Yvon
 * @since : 2022-12-06
 */
public class PropertyValues {

    /**
     * 属性值列表
     */
    private final List<PropertyValue> propertyValueList = new ArrayList<>();

    /**
     * 添加属性值
     *
     * @param pv
     */
    public void addPropertyValue(PropertyValue pv) {
        this.propertyValueList.add(pv);
    }

    /**
     * 获取属性值
     *
     * @return {@code PropertyValue[] }
     */
    public PropertyValue[] getPropertyValues() {
        return this.propertyValueList.toArray(new PropertyValue[0]);
    }

    /**
     * 获取属性值
     *
     * @param propertyName 属性名
     * @return {@code PropertyValue }
     */
    public PropertyValue getPropertyValue(String propertyName) {
        for (PropertyValue pv : this.propertyValueList) {
            if (pv.getValue().equals(propertyName)) {
                return pv;
            }
        }
        return null;
    }
}
